<template>
	<view class="enroll-view">
		<view class="center-view">
			<button class="long-button" type="primary" @click="newTemplet">新建模板</button>
			<view @click="view(templet.id)" class="templet-item dashboard" v-for="templet in templets" :key="templet.id">
				<view class="templet-title">{{templet.title}}</view>

				<!-- <vie{{templet.author}}- -->
				<view class="templet-time">{{formatDatetime(new Date(templet.subTime))}}</view>
				<view class="templet-status">{{templet.status==0?'仅自己可见':'所有人可见'}}</view>
				<!-- <button class="templet-button" @click.stop="deleteTemplet(templet.id)">删除</button> -->
				<image class="templet-button" @click.stop="deleteTemplet(templet.id)" style="height:70upx;margin-top:20upx;margin-right:-20upx;" src="../../static/delete.svg"></image>
			</view>
		</view>
			
	</view>
</template>


<script>
	import formatDatetime from "../../common/zdateutil.js"
	export default {
		data: function () {
			return {
				templets : [],//[{'id':'test1','title':'test1','author':'zekdot','subTime':1586347105849,'status':0}],
				formatDatetime : null
				// timeLimit : ""
			}
		},
		onLoad : function(){
			this.formatDatetime = formatDatetime.formatDatetime;
			var vm = this;
			var param = {'lastId':'','length':10};
			this.$get(this.enrollurl + '/enroll/selfTemplets',param,function(res){
				var data = res.data;
				if(data.code != 0){
					uni.showModal({
						title : '错误',
						content : data.message,
						showCancel : false
					})
					return ;
				}
				vm.templets = data.object;
			});
		},
		methods: {
			newTemplet : function(){
				uni.navigateTo({
					url : 'newTemplet'
				})
			},
			view : function(id){
				uni.navigateTo({
					url : 'viewTemplet?id=' + id
				})
			},
			deleteTemplet(id){
				var vm = this;
				uni.showModal({
					title : '删除项目',
					content : '您确定删除id为' + id + '的项目吗？',
					success : function(res){
						if(res.confirm){
							var param = {'id' : id};
							vm.$post(vm.enrollurl + '/enroll/deleteTemplet',param,function(res){
								var data = res.data;
								if(data.code != 0){
									uni.showModal({
										title : '错误',
										content : data.message,
										showCancel : false
									})
								}
								for(var i=0;i<vm.templets.length;i++){
									if(vm.templets[i].id == id){
										vm.templets.splice(i,1);
									}
								}
								uni.showToast({
									title: '删除成功！'
								})
							})
						}
					}
				})
			}
		}
	}
</script>

<style>
	@import "../../common/zcss.css";
.row-arrange{
		flex-direction: row;
	}
	.enroll-view{
		width: 100%;
		flex-direction: column;
	}
	.center-view{
		width:100%;
		display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
	}
	/* .new-item-view{
		background-color: aqua;
		margin-bottom: 10upx;
	} */
	.templet-item{
		border: 1upx solid gray;
		height: 150upx;
		position: relative;
		width: 99%;
		margin-bottom: 3upx;
		/* background-color: white; */
		/* background-color: azure; */
	}
	/* .enroll-button{
		position: absolute;
		font-size:40upx;
		height:80upx;
		width: 160upx;
		right: 1%;
	} */
	.templet-time{
		position: absolute;
		font-size: 20upx;
		color: gray;
		left: 1%;
		bottom: 0%;
	}
	.templet-status{
		position: absolute;
		font-size: 20upx;
		right: 1%;
		bottom: 1%;
	}
	.templet-button{
		position: absolute;
		font-size:40upx;
		height:80upx;
		width: 160upx;
		right: 1%;
	}
	.templet-title{
		font-size: 50upx;
		position: absolute;
		top: 1%;
		left: 1%;
	}
</style>
